<?php
use Phalcon\Mvc\Controller;
use WSDL\WSDLCreator;
use WSDL\XML\Styles\RpcEncoded;
use WSDL\XML\Styles\DocumentLiteralWrapped;


class AuthController extends Controller
{

	public function indexAction()
	{
ini_set("soap.wsdl_cache_enabled", 0);
		$wsdl = new WSDLCreator('SimpleSoapServer', 'http://192.168.0.205:99/auth');
		$wsdl->setNamespace("http://foo.bar/")->setBindingStyle(new DocumentLiteralWrapped());
		if(1==1){
			$wsdl->renderWSDL();
			exit;
		}
		$wsdl->renderWSDLService();

		$server = new SoapServer('http://192.168.0.205:99/auth', array(
			'uri' => $wsdl->getNamespaceWithSanitizedClass(),
			'location' => $wsdl->getLocation(),
			'style' => SOAP_DOCUMENT,
			'use' => SOAP_LITERAL,
			'features' => SOAP_SINGLE_ELEMENT_ARRAYS
		));
		$server->setObject(new DocumentLiteralWrapper(new SimpleSoapServer()));
		$server->handle();
		exit;
	}
	
	public function wsdlAction()
	{

		$wsdl = new WSDLCreator('SimpleSoapServer', 'http://192.168.0.205/loginSystem/auth/wsdl');
		$wsdl->setNamespace("http://oa.xk.com/")->setBindingStyle(new RpcEncoded());

		$wsdl->renderWSDLService();

		$server = new SoapServer('http://192.168.0.205/loginSystem/auth/wsdl', array(
			'uri' => $wsdl->getNamespaceWithSanitizedClass(),
			'location' => $wsdl->getLocation(),
			'style' => SOAP_RPC,
			'use' => SOAP_ENCODED
		));
		$server->setClass('SimpleSoapServer');
		$server->handle();
	}

}

class SimpleSoapServer
{
    /**
     * @param string $name
     * @param int $age
     * @return string $nameWithAge
     */
    public function getNameWithAge($name, $age)
    {
        return 'Your name is: ' . $name . ' and you have ' . $age . ' years old';
    }

    /**
     * @param string[] $names
     * @return string $userNames
     */
    public function getNameForUsers($names)
    {
        return 'User names: ' . implode(', ', $names);
    }

    /**
     * @param int $max
     * @return string[] $count
     */
    public function countTo($max)
    {
        $array = array();
        for ($i = 0; $i < $max; $i++) {
            $array[] = 'Number: ' . ($i + 1);
        }
        return $array;
    }

    /**
     * @param string[] $user
     * @return sting[] $user
     */
    public function syncUser($user){
        return $user;
    }

    /**
     * @param string $user
     * @return sting $user
     */
    public function backUser($user){
        return $user;
    }
}

